import NumberSelector from './NumberSelector';
import TimeSelector from './TimeSelector';
import TimeSelector2 from './TimeSelector2';
import RemarkSelector from './RemarkSelector';
import HighwaySelector from './HighwaySelector';
import CartypeSelector from './CartypeSelector';
import ContactsSelector from './ContactsSelector';
import DairenTypeSelector from './DairenTypeSelector';
import WaitingDateSelector from './WaitingDateSelector';
import ChargeDetail from './ChargeDetail';
import store from '@/store';
import router from '@/router';
import Vue from 'vue';
const TimeConstructor = Vue.extend(TimeSelector);
const TimeConstructor2 = Vue.extend(TimeSelector2);
const NumberConstructor = Vue.extend(NumberSelector);
const RemarkConstructor = Vue.extend(RemarkSelector);
const HighwayConstructor = Vue.extend(HighwaySelector);
const CartypeConstructor = Vue.extend(CartypeSelector);
const ContactsConstructor = Vue.extend(ContactsSelector);
const DairenTypeConstructor = Vue.extend(DairenTypeSelector);
const WaitingDateConstructor = Vue.extend(WaitingDateSelector);
const ChargeDetailConstructor = Vue.extend(ChargeDetail);
function createVM(constructor, opt) {
  return new Promise((resolve, reject) => {
    let params = {
      value: true
    };
    Object.assign(params, opt);
    let vm = new constructor({
      propsData: params,
      store,
      router
    }).$mount();
    if (vm) {
      vm.$on('cancel', () => {
        vm.$destroy();
        reject();
      });
      vm.$on('submit', data => {
        resolve(data);
        vm.$destroy();
      });
    }
  });
}
const Popup = {
  createTimeSelector2() {
    return createVM(TimeConstructor2);
  },
  createTimeSelector() {
    return createVM(TimeConstructor);
  },
  createNumberSelector(param) {
    return createVM(NumberConstructor, { max: param });
  },
  createRemarkSelector(param) {
    return createVM(RemarkConstructor, { type: param });
  },
  createHighwaySelector() {
    return createVM(HighwayConstructor);
  },
  createCartypeSelector() {
    return createVM(CartypeConstructor);
  },
  createContactsSelector() {
    return createVM(ContactsConstructor);
  },
  createTypeSelector() {
    return createVM(DairenTypeConstructor);
  },
  createWaitingDateSelector() {
    return createVM(WaitingDateConstructor);
  },
  createChargeDetail(costid) {
    return createVM(ChargeDetailConstructor, { costId: costid });
  }
};
export default Popup;
